package com.kun.companion.controller;

import com.kun.companion.core.AbstractController;
import com.kun.companion.core.context.annotation.InjectBean;
import com.kun.companion.core.domain.dto.StageSize;
import com.kun.companion.core.queue.ui.button.AwaitEventButton;
import com.kun.companion.core.thread.ComThreadPool;
import com.kun.companion.core.ui.component.AiChatContainer;
import com.kun.companion.core.ui.view.KunTab;
import com.kun.companion.core.ui.view.KunTabPane;
import com.kun.companion.core.util.ComUtil;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

/**
 * TODO
 *
 * @author gzc
 * @since 2025/2/8 14:53
 **/
public class TestController extends AbstractController {
    @FXML
    public KunTabPane kunTabPane;
    @InjectBean
    private ComThreadPool comThreadPool;

    @Override
    protected StageSize getMainStageSize() {
        return new StageSize(1200, 1000,
                100, 100,
                ComUtil.DIMENSION.getWidth(), ComUtil.DIMENSION.getHeight());
    }

    AiChatContainer aiChatContainer;

    @Override
    protected void initLayout() {
//        chatBox = new AiChatPane();
//        BaseTextArea baseTextArea = new BaseTextArea("给坤坤发送消息吧", true);
//        baseTextArea.setPrefHeight(200);
        aiChatContainer = new AiChatContainer();
        // 随窗口大小自适应
        kunTabPane.setPrefSize(rootNode.getPrefWidth(), rootNode.getPrefHeight());
        kunTabPane.setPrefSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE);
        KunTab tab1 = new KunTab("AI坤坤");
        tab1.setContentHandler((region -> {
//            AwaitEventButton awaitEventButton = new AwaitEventButton("发送");
//            awaitEventButton.action(() -> {
//                String markdownContent = """
//                        # 欢迎使用AI助手！
//                        **功能列表**：
//                        ```java
//                        public static void main(String[] args) {
//                            System.out.println("Hello World!");
//                        }
//                        ```
//                        ```java
//                        public static void main(String[] args) {
//                            System.out.println(" 大声大声道!");
//                        }
//                        ```
//                        > 支持以下特性：
//                        - 代码高亮
//                        - 即时停止
//                        - 样式定制
//                        """;
//                String text = DeepSeekService.sendAndResult("给我一段最简单的java代码");
//                chatBox.startTyping(markdownContent);
//            });
//            AwaitEventButton awaitEventButton1 = new AwaitEventButton("停止");
//            awaitEventButton1.action(() -> chatBox.stopTyping());
//            ((VBox) region).getChildren().setAll(chatBox, baseTextArea, awaitEventButton, awaitEventButton1);
            return aiChatContainer;
        }));
        kunTabPane.addTab(tab1);

//        KunTab tab2 = new KunTab("按需加载");
//        tab2.setContentHandler((region -> {
//            if (region == null) {
//                region = new VBox();
//                ((VBox) region).setAlignment(Pos.CENTER);
//            }
//            CommandExecutor.CommandResult commandResult = CommandExecutor.executeCommand(ListUtil.toList("ffmpeg", "-version"), 1);
//            System.out.println(commandResult);
//            return region;
//        }));
//        kunTabPane.addTab(tab2);


    }


    @Override
    protected void reactiveWidth(double mainBoxWidth) {

    }

    @Override
    protected void reactiveHeight(double mainBoxHeight) {

    }
}
